using UnityEngine;

public class PlayerAIState_ChaseBall : State<PlayerAI>
{
	public static PlayerAIState_ChaseBall instance;

	private PlayerAIState_ChaseBall()
	{
	}

	public static PlayerAIState_ChaseBall getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerAIState_ChaseBall();
		}
		return instance;
	}

	public override void enter(PlayerAI owner)
	{
		base.enter(owner);
		owner.player.do_run();
	}

	public override void fixedUpdate(PlayerAI owner)
	{
		base.fixedUpdate(owner);
		if (owner.player.isInState(PlayerStateBehavior_Dribble_Stay.getInstance()))
		{
			Instance<Court>.instance.OnGrabedRebound(owner.player);
		}
		else if (owner.player.paraPlayer.IsOffense())
		{
			owner.do_defense_defense();
		}
		else
		{
			if (owner.player.isInState(PlayerStateBehavior_Rebound.getInstance()))
			{
				return;
			}
			if (Instance<Ball>.instance.isInState(BallState_Rebound.getInstance()) && Instance<Ball>.instance.isGetBall(owner.player.getPosition()))
			{
				Vector3 position = Instance<Ball>.instance.getPosition();
				if (position.y > 2.5f)
				{
					owner.player.do_rebound();
				}
				else
				{
					Instance<Court>.instance.OnGrabedRebound(owner.player);
				}
			}
			else
			{
				GameHelper.MoveTo(owner.player, MathHelper.setY(Instance<Ball>.instance.getPosition(), 0f), owner.player.getMoveSpeed(), isLookAtTargetPos: true);
				owner.player.do_run();
			}
		}
	}
}
